package com.dekarrin.scraton;

import java.util.Date;
import com.dekarrin.util.StringPadder;

public abstract class ScriptInstruction implements Comparable<ScriptInstruction> {

	private static long highestStamp = -1;

	private Date timestamp;
	
	protected ScriptFormat format;

	/**
	 * @param ms
	 * If this is -1, then it is automatically set to the next sequential from
	 * the highest already set.
	 */
	public ScriptInstruction(long ms) {
		long time = (ms != -1) ? ms : highestStamp + 1;
		if (time > ScriptInstruction.highestStamp) {
			ScriptInstruction.highestStamp = time;
		}
		timestamp = new Date(time);
		this.format = null;
	}
	
	public void setFormat(ScriptFormat format) {
		this.format = format;
	}
	
	public int compareTo(ScriptInstruction s2) {
		return timestamp.compareTo(s2.timestamp);
	}
	
	protected String getClearLeftMargin() {
		return getClearMargin(format.leftMarginWidth);
	}
	
	protected String getClearRightMargin() {
		return getClearMargin(format.rightMarginWidth);
	}
	
	private String getClearMargin(int marginWidth) {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < marginWidth; i++) {
			builder.append(" ");
		}
		return builder.toString();
	}
}